package com.i3nu.contacts.activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.i3nu.contacts.activity.R;
import com.i3nu.contacts.model.Constants.ContactsSettings;
public class ContactsPreferencesActivity extends Activity implements CheckBox.OnCheckedChangeListener , View.OnClickListener{
    SharedPreferences settings;
    SharedPreferences.Editor editor;
    
    CheckBox mCbDisplayOption;
    Button mBtnDone;
    Button mBtnDiscard;
    
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.contacts_preferences);
        
        this.settings=this.getSharedPreferences(ContactsSettings.FILE_NAME,Activity.MODE_PRIVATE);
        this.editor=settings.edit();
        
        mCbDisplayOption= (CheckBox) findViewById(R.id.checkbox_display_option);
        mCbDisplayOption.setChecked(settings.getBoolean(ContactsSettings.DISPLAY_OPTION, false));
        mCbDisplayOption.setOnCheckedChangeListener(this);
        
        mBtnDone=(Button)findViewById(R.id.btn_done);
        mBtnDiscard=(Button)findViewById(R.id.btn_discard);
        mBtnDone.setOnClickListener(this);
        mBtnDiscard.setOnClickListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // TODO Auto-generated method stub
        if(buttonView==mCbDisplayOption){
            editor.putBoolean(ContactsSettings.DISPLAY_OPTION, isChecked); 
        }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if(v==mBtnDone){
            editor.commit();
            this.finish();
        }
        else if(v==mBtnDiscard){
            this.finish();
        }
    }

    
}
